var loginBtn = document.getElementById('loginBtn');
var backBtn = document.getElementById('backBtn');

loginBtn.addEventListener('click', function() {
  var username = document.getElementById('username').value;
  var password = document.getElementById('password').value;
  var reg = /^[1-9]\d*$/;
  if(!reg.test(username)){
    alert("请输入正确的格式！");
  }
  else{
  console.log(username);
  console.log(password);
  // 这里可以编写后端调用的代码，验证用户名和密码是否匹配数据库
  $.ajax({
    url: '/management/loginservlet/mngLogin',
    method: 'POST',
    data: {
      username: username,
      password: password
    },
    success: function(response) {
      // 处理响应数据
      if (response.flag) {
              // 登录成功
              console.log(response.errorMsg);
              alert(response.errorMsg);
              window.location.href = "mnglogin_menu.html";
            } else {
              // 登录失败
              console.log(response.errorMsg);
              alert(response.errorMsg);
            }
    },
    error: function(xhr, status, error) {
      // 处理错误
      console.log(error);
    }
  });
  }
});

backBtn.addEventListener('click', function() {
  // 返回上一个页面的操作
  window.history.back();
});

var content = document.querySelector('.content');
content.addEventListener('mouseenter', function() {
  content.style.transition = 'background-color 0.3s';
  content.style.backgroundColor = 'rgba(230,230,230,0.6)'; // 将透明度更改为 0.5，使背景色加深
});

content.addEventListener('mouseleave', function() {
  content.style.transition = 'background-color 0.3s';
  content.style.backgroundColor = 'rgba(230,230,230,0.2)'; // 将透明度恢复为 0.2，使背景色变浅
});

var container = document.querySelector('.container');

/* 监听鼠标进入.container元素事件 */
container.addEventListener('mouseleave', function() {
  container.style.transition = 'opacity 0.3s';
  container.style.opacity = '0.2';
});

container.addEventListener('mouseenter', function() {
  container.style.transition = 'opacity 0.3s';
  container.style.opacity = '1';
});

$(document).keydown(function(event) {
  if (event.keyCode == 13) { // 13代表回车键的键码
    $('#loginBtn').click();
  }
});

